#include <Measurement.h>

Measurement::Measurement (int amount, const Unit& unit):amount(amount), unit(unit)
{
}

bool Measurement::operator == (const Measurement& anotherMeasurement)  const
{
  return (unit.isSameType(anotherMeasurement.unit))
     && (getAmountInBaseUnit() == anotherMeasurement.getAmountInBaseUnit());
}


bool Measurement::operator != (const Measurement& anotherMeasurement) const
{
  return !(*this == anotherMeasurement);
}

Measurement Measurement::operator + (const Measurement& measurement) const
{
  if (unit.isSameType(measurement.unit))
    return Measurement(getAmountInBaseUnit() + measurement.getAmountInBaseUnit(), unit.getBaseUnit());
  else
    return Measurement(0, INVALID);
}

int Measurement::getAmountInBaseUnit() const
{
  return unit.getAmountInBaseUnit(amount);
}


const std::string Measurement::getAndPrint(const PrintFormat&  format) const
{
  return unit.getAndPrint(format, amount); 
}
